package csx.study.demo.config;

import csx.study.demo.interceptor.JwtTokenUserInterceptor;
import csx.study.demo.interceptor.LoginInterceptor;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器配置
 */
//模板方法模式，父类或接口提供一些方法的默认实现，然后子类可以重写某些方法
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Resource
    private LoginInterceptor loginInterceptor;

    @Resource
    private JwtTokenUserInterceptor jwtTokenUserInterceptor;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtTokenUserInterceptor)
                .excludePathPatterns(
                        //登录注册不该拦截
                        "/user/code",
                        "/user/login",

                        //部分界面不登陆也应该查看
                        //反面案例：京东的有些东西不登陆就不给看
                        "/blog/hot",
                        "/shop/**",
                        "/voucher/**",
                        "/shop-type/**",
                        "/upload/**"
                );

//        registry.addInterceptor(loginInterceptor)
//
//                .excludePathPatterns(
//                        //登录注册不该拦截
//                        "/user/code",
//                        "/user/login",
//
//                        //部分界面不登陆也应该查看
//                        //反面案例：京东的有些东西不登陆就不给看
//                        "/blog/hot",
//                        "/shop/**",
//                        "/voucher/**",
//                        "/shop-type/**",
//                        "/upload/**"
//                );
    }
}
